from transformers import AutoModelForCausalLM, AutoTokenizer


def Qwen3_coder_example(qwen3_coder_model_id="Qwen/Qwen3-480B-A35B-Instruct"):
    # load the tokenizer and the model
    tokenizer = AutoTokenizer.from_pretrained(qwen3_coder_model_id)
    model = AutoModelForCausalLM.from_pretrained(
        qwen3_coder_model_id, torch_dtype="auto", device_map="auto"
    )

    # prepare the model input
    prompt = "Write a quick sort algorithm."
    messages = [{"role": "user", "content": prompt}]
    text = tokenizer.apply_chat_template(
        messages,
        tokenize=False,
        add_generation_prompt=True,
    )
    model_inputs = tokenizer([text], return_tensors="pt").to(model.device)

    # conduct text completion
    generated_ids = model.generate(**model_inputs, max_new_tokens=65536)
    output_ids = generated_ids[0][len(model_inputs.input_ids[0]) :].tolist()

    content = tokenizer.decode(output_ids, skip_special_tokens=True)

    print("content:", content)
